package com.zjm.creational.prototype.deepclone;

public class Client {
    public static void main(String[] args) {
        DeepPrototype deepPrototype = new DeepPrototype();
        deepPrototype.setName("孙悟空");
        deepPrototype.setDeepCloneableTarget(new DeepCloneableTarget("妖怪", "妖怪的类"));

        // 方式1：使用clone
        DeepPrototype deepPrototype1 = (DeepPrototype) deepPrototype.clone();
        DeepPrototype deepPrototype2 = (DeepPrototype) deepPrototype.clone();
        System.out.println(deepPrototype.toString() + "---" + deepPrototype.getDeepCloneableTarget());
        System.out.println(deepPrototype1.toString() + "---" + deepPrototype1.getDeepCloneableTarget());
        System.out.println(deepPrototype2.toString() + "---" + deepPrototype2.getDeepCloneableTarget());

        // 方式2：使用序列化
        DeepPrototype deepPrototype3 = (DeepPrototype) deepPrototype.deepClone();
        DeepPrototype deepPrototype4 = (DeepPrototype) deepPrototype.deepClone();
        System.out.println(deepPrototype.toString() + "---" + deepPrototype.getDeepCloneableTarget());
        System.out.println(deepPrototype3.toString() + "---" + deepPrototype3.getDeepCloneableTarget());
        System.out.println(deepPrototype4.toString() + "---" + deepPrototype4.getDeepCloneableTarget());
    }
}
